/*
 * MessageConsumer.h
 *
 *  Created on: Jul 19, 2013
 *      Author: m
 */

#ifndef MESSAGECONSUMER_H_
#define MESSAGECONSUMER_H_

#include "MessageQueue.h"
#include "FixedLengthMessage.h"

namespace communication
{

template <class T> class MessageConsumer
{
protected:
    MessageQueue<FixedLengthMessage> m_channel;

public:
    MessageConsumer( std::string channelName ) :
        m_channel( channelName )
    {
    }

    virtual ~MessageConsumer()
    {
    }

    void consume( messageType_t type, T &data )
    {
        FixedLengthMessage msg;

        msg = m_channel.get( type );

        memcpy( &data, msg.getData(), sizeof(T) );
    }
};

} /* namespace communication */
#endif /* MESSAGECONSUMER_H_ */
